import dayjs from 'dayjs'
import { z } from 'zod'

export const dayjsStrValidator = z
	.string()
	.refine(value => dayjs(value).isValid(), {
		message: 'Неверный форматы даты',
		path: [] // This is necessary
	})
	.transform(value => dayjs(value))

export const dayjsValidator = z.custom<dayjs.Dayjs>(
	value => dayjs.isDayjs(value),
	'Expected Dayjs object, received something else'
)

export const nullableString = z
	.string()
	.nullable()
	.transform(value => (value === null ? '' : value))
